﻿using System;
using System.Activities;
using Reactor.Workflow.Extensions;

namespace Reactor.Workflow.Activities
{
    public class GetPersistedProperty<T> : CodeActivity<T>
    {
        [RequiredArgument]
        public InArgument<string> PersistedPropertyName { get; set; }

        protected override T Execute(CodeActivityContext context)
        {
            var ext = context.GetExtension<PersistedPropertiesExtension>();
            if (ext == null) throw new InvalidOperationException("No PersistedPropertiesExtension found.");

            return ext.GetPersistedPropertyValue<T>(context.WorkflowInstanceId, context.GetValue(PersistedPropertyName));
        }
    }
}
